//
//  Kylin_TopicItem.m
//  03-BuDeJie
//
//  Created by Kylin on 16/2/29.
//  Copyright © 2016年 kylin. All rights reserved.
//

#import "Kylin_TopicItem.h"

@implementation Kylin_TopicItem

- (CGFloat)cellHeight{
    
    if (_cellHeight) return _cellHeight;
    
    // 头像
    _cellHeight += 55;
    
    // 文字
    CGFloat textMaxW = Kylin_ScreenW - 2 * Kylin_CommonMargin;
    CGSize testMaxSize = CGSizeMake(textMaxW, MAXFLOAT);
    _cellHeight += [self.text boundingRectWithSize:testMaxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15]} context:nil].size.height + Kylin_CommonMargin;
    
    //计算中间内容
    if (self.type != Kylin_TopicTypeWrod) {
        CGFloat middleW = textMaxW;
        CGFloat middleH = middleW * self.height / self.width; // 等比例缩放
        if(middleH >= Kylin_ScreenH){
            middleH = 200;
            self.bigPicture = YES;
        }
        CGFloat middleY = _cellHeight;
        CGFloat middleX = Kylin_CommonMargin;
        
        self.middleFrame = CGRectMake(middleX, middleY, middleW, middleH);
        
        _cellHeight += middleH + Kylin_CommonMargin;
    }
    
    // 最热评论
    if (self.top_cmt.count) {
        
        _cellHeight += 18;
        NSDictionary *dict = self.top_cmt.firstObject;
        NSString *content = dict[@"content"];
        
        if (content.length == 0) {
            content = @"[语音信息]";
        }
        
        NSString *userName = dict[@"user"][@"username"];
        NSString *topCmtText = [NSString stringWithFormat:@"%@ : %@",userName,content];
        _cellHeight += [topCmtText boundingRectWithSize:testMaxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15]} context:nil].size.height;
        _cellHeight += Kylin_CommonMargin;
    }
    
    
    // 加上工具条高度
    _cellHeight += 35 + Kylin_CommonMargin;
    
    return _cellHeight;
}
@end
